package logic

import (
	"context"
	"fmt"
	"go-zero-demo/product/api/internal/svc"
	"go-zero-demo/product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) DetailLogic {
	return DetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DetailLogic) Detail(req types.DetailRequest) (resp *types.DetailResponse, err error) {
	fmt.Println("能到达这里吗detaillogic")
	if req.Id == 0 {
		fmt.Println("参数错误！")
	}
	fmt.Println(req.Id)
	userInfo, err := l.svcCtx.ProductModel.FindOne(req.Id)
	fmt.Println(userInfo)
	return &types.DetailResponse{
		Id:  userInfo.Id,
		Name: userInfo.Name,
		Desc: userInfo.Desc,
		Stock:  userInfo.Stock,
		Amount: userInfo.Amount,
		Status: userInfo.Status,
	}, nil
}
